package com.hjy.servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.hjy.service.UserService;
import com.hjy.service.impl.UserServiceImpl;

public class UserServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	private UserService userService = new UserServiceImpl();
       
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		response.setContentType("text/html;charset=utf-8");
		String action = request.getParameter("action");
		if (action != null && action.length()>0 && action.equals("active")) {
				active(request,response);
		} else {
			response.getWriter().print("请不要乱来！！！");
		}
		
	}

	private void active(HttpServletRequest request, HttpServletResponse response) throws IOException {
		// 拿参数
		String code = request.getParameter("code");
		String account = request.getParameter("account");
		
		boolean result = userService.active(account,code);
		
		if (result) {
			response.getWriter().print("验证通过！！！");
		} else {
			response.getWriter().print("验证失败！！！");
		}
		
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

}
